<!-- 全部订单 -->
<template>
	<view style="overflow-x: hidden;">
	<view class="avatar-info">
		<input type="text"
		  placeholder="请输入运单号、品名、收货人电话查询"
		  v-model="inputValue"
		  class="contact-info"
		  @input="searchItemsByKeyword"></input>
	</view>
<view v-if="items.length === 0" class="empty-state">
	    <image src="/../../../static/空数据.png" style="height:180px;width: 180px;">
		<view style="font-size: 20px;text-align: center;">暂无数据!</view>
	</view>
	<view v-else>
	<view v-for="(item, index) in queryResult" :key="index" class="content-list1" >
		<view style="border-bottom: 1px solid #ccc;">
			<view class="avatar-text" style="justify-content: space-around;margin-left: 10px;">
			<view style="display: flex;flex-direction: row;align-items: center;">
				<text class="yundan" >运 单 号</text>
				<text class="number" style="display: inline-block;width: 110px;">{{ item.waybillNumber }}</text>
				<text class="deliver"  v-if="item.status===0">新</text>
				<text class="deliver"  v-if="item.status===2">又发</text>
				<text class="deliver"  v-if="item.status===1">发</text>
				<text class="deliver"  v-if="item.status===3">到</text>
				<text class="make" v-if="item.predictStatus===1" style="text-align: center;">预</text>
				<text class="dispatch" v-if="item.paidanStatus===1" style="text-align: center;">派</text>
				<text class="cargo" v-if="item.tihuoStatus===1" style="text-align: center;">提</text>
			</view>
			<view style="display: flex;flex-direction: row;align-items: center;">
				<text class="price" style="text-align: center;">费用</text>
				<text class="money" >￥{{item.sanbaoCost.toFixed(2)}}</text>
			</view>
			</view>
		</view>
		<view class="content-list-1">
			<view class="avatar-list">
			<text class="shipment">货件信息</text>
			<text class="algebra" v-if="item.number!=null">{{item.number}}件</text>
			<text class="one"> | </text>
			<text class="kg" v-if="item.weight!=null">{{item.weight}}kg</text>
			<text class="meter" v-if="item.volume!=null">{{item.volume}}m³</text>
			</view>
		</view>
		<view class="content-list-2">
			<view class="avatar-list">
			<text class="artNo">货号</text>
			<text class="artNumber" v-if="item.articleNumber!=null">{{item.articleNumber}}</text>
			</view>
		</view>
		<view class="content-list-3">
			<view class="avatar-list">
			<text class="package">包装内容</text>
			<text class="artNumber" v-if="item.installContent!=null">{{item.installContent}}</text>
			</view>
		</view>
		<view class="content-list-9">
			<view class="avatar-list">
			<text class="options" style="color: red;">运单类型</text>
			<text class="delivery-options" v-if="item.type===1" style="font-weight: bold;color:red;">送货单</text>
			<text class="delivery-options" v-if="item.type===2" style="font-weight: bold;color:red;">派车单</text>
			<text class="delivery-options" v-if="item.type===3" style="font-weight: bold;color:red;">三包单</text>
			</view>
		</view>
		<view class="content-list-4">
			<view class="avatar-list">
			<text class="options">配送方式</text>
			<text class="delivery-options" v-if="item.receiving!=null">{{item.receiving}}</text>
			</view>
		</view>
		<view class="content-list-5">
			<view class="avatar-list">
			<text class="options">派单人</text>
			<text class="delivery-options" v-if="item.sender!=null">{{item.sender}}</text>
			</view>
		</view>
		<view class="content-list-6">
			<view class="avatar-list">
			<text class="options">收货人</text>
			<text class="delivery-options"  v-if="item.putUserName!=null">{{item.putUserName}}</text>
			<!-- <text class="delivery-number" v-if="item.putPhone!=null" @click="call(item,index)">{{item.putPhone}}</text> -->
				<text class="delivery-number" v-if="item.putPlane!=null" @click="callPhone(item.putPlane)">{{item.putPlane}}</text>
			<text class="delivery-icon"><image src="../../../static/电话.png"></image></text>
			</view>
		</view>
		<view class="content-list-7" >
			<view class="avatar-list"  style="display: flex;flex-direction: row;align-items: center;position: relative;">
			<text class="options">送货地址</text>
			<text class="delivery-options" v-if="item.destinationStation!==null">{{item.destinationStation}}<text v-if="item.putDetailAddress!=null">{{item.putDetailAddress}}</text></text>
			<view class="delivery-axis" @click="HeadMap(index,item)"><image src="../../../static/坐标.png"></image></view>
			</view>
		</view>
		<view class="content-list-8">
			<view class="avatar-list">
			<text class="options">提货电话</text>
			<text class="delivery-options" style="color: #00aaff;"  v-if="item.masterPorterContact!=null" @click="call2(item,index)">{{item.masterPorterContact}}</text>
			<text class="delivery-icon" v-if="item.masterPorterContact!=null"><image src="../../../static/电话.png"></image></text>
			</view>
		</view>
		<view class="content-list-9">
			<view class="avatar-list">
			<text class="options">提货地址</text>
			<text class="delivery-options" v-if="item.masterPorterAddress!=null">{{item.masterPorterAddress}}</text>
			<text class="delivery-options" v-if="item.deliveryDistance!=null" style="color: #ffb300;"> {{item.deliveryDistance}} KM</text>
			</view>
		</view>
		<view class="content-list-10">
			<view class="avatar-list">
			<text class="options">厂家信息</text>
			<text class="delivery-options" v-if="item.sendUserName!=null">{{item.sendUserName}}</text>
			</view>
		</view>
		<view class="content-list-11">
			<view class="avatar-list">
			<text class="options">派单日期</text>
			<text class="delivery-options" v-if="item.paidanTime!=null">{{ formatDate(item.paidanTime) }}</text>
			</view>
		</view>
		<view class="content-list-12">
			<view class="avatar-list">
			<text class="options">预约日期</text>
			<text class="delivery-options" v-if="item.predictTime!=null">{{formatDate(item.predictTime)}}</text>
			</view>
		</view>
		<view class="content-list-13">
			<view class="avatar-list13">
			<text class="options">分单信息</text>
			<text class="delivery-options"></text>
			</view>
		</view>
		<view class="content-list-14">
			<view class="avatar-button">
			<button class="abnormal" @click="abnormalToOrder(item)">☇异常</button>
			<button class="lading" v-if="currentIndex==1">√分单</button>
			<button class="booked" v-if="currentIndex==1 || currentIndex==2" @click="showInputModal(item, index)" >☇预约</button>
			<button class="details" v-if="currentIndex!=1 &&  item.type!==2" @click="detailsToOrder(item,index)">√详情</button>
			</view>
		</view>
		<view class="end"></view>
		</view>
	</view>
		
	<view>
		<view class="end2" v-if="items.length > 0" ></view>
	</view>
	<view class="content-list-15">
		<view class="avatar-order">
		<text>合计： {{items.length}}条记录</text>
		</view>
	</view>
	<BillModal ref="inputModal"  :businessId="businessId"  @confirm="confirm" :phone="phone"/>
	</view>
</template>

<script> 
    import BillModal from '@/pages/components/all/all.vue';	
	export default {
		components: {
			BillModal
		 },
		data() {
			return {
				 pageTitle: '页面标题',
				 items:[],
				 businessId:'',
				 queryResult:[],
				 inputValue:''
			}
		},
		mounted(){
			this.showInputModal();
		},
		watch: {
			items() {
			    this.searchItemsByKeyword();
			  }
		},
		props: {
			 phone: {
				 type: String,
				 required: true
			 }
		    },
		methods: {
			detailsToOrder(item,ndex){
				const selectedItem = item;
				uni.navigateTo({	
					url: '/pages/index/details/details?id='+selectedItem.businessId // 请注意，这里的url应为相对路径，且以'/'开头
				});
			},
			HeadMap(index,item){
				console.log("地图");
				const address=item.putDetailAddress
				const latitudeId=NULL
				console.log(latitudeId);
				if(address!==undefined &&address!==''){
				uni.navigateTo({
					url: '/pagesA/index/map/map?address='+address+'&latitudeId='+latitudeId// 请注意，这里的url应为相对路径，且以'/'开头
				});
				}
			},
			call2(item,index){
				const phoneNumber=item.masterPorterContact
				this.callPhone(phoneNumber)
			},
			call(item,index){
				const phoneNumber=item.putPhone
				this.callPhone(phoneNumber)
			},
			callPhone(phoneNumber) {
			        // 检查传入的电话号码是否为空或格式不正确
			        if (!phoneNumber || typeof phoneNumber !== 'string' || !/^\d+$/.test(phoneNumber)) {
			            uni.showToast({
			                title: '电话号码格式不正确',
			                icon: 'none'
			            });
			            return;
			        }
			 
			        // 使用uni.makePhoneCall发起电话拨打请求
			        uni.makePhoneCall({
			            phoneNumber: phoneNumber, // 此处填写要拨打的电话号码
			            success: function () {
			                // 用户确认拨打后，此回调会被触发
			                console.log('用户已确认拨打');
			            },
			            fail: function (err) {
			                // 用户取消拨打或拨打电话失败时，此回调会被触发
			                console.error('拨打电话失败：', err);
			                uni.showToast({
			                    title: '拨打电话失败，请检查您的设置或重试',
			                    icon: 'none'
			                });
			            }
			        });
			    },
					abnormalToOrder(index){
						const selectedItem = index.businessId
						console.log(selectedItem)
						uni.navigateTo({
							url: '/pages/index/abnormal/abnormal?id='+selectedItem // 请注意，这里的url应为相对路径，且以'/'开头
						});
					},
			formatDate(dateStr) {
			    const date = new Date(dateStr);
			    // 提取年、月、日、小时、分钟和秒
			    const year = date.getFullYear();
			    const month = String(date.getMonth() + 1).padStart(2, '0'); // 月份从0开始，所以需要加1，并且用padStart来确保始终是两位数
			    const day = String(date.getDate()).padStart(2, '0'); // 同上，用padStart来确保始终是两位数
			    const hours = String(date.getHours()).padStart(2, '0');
			    const minutes = String(date.getMinutes()).padStart(2, '0');
			    const seconds = String(date.getSeconds()).padStart(2, '0');
			    
			    // 返回格式化后的日期字符串
			    return `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`;
			  },
			searchItemsByKeyword() {
				 let keyword = '';
				  if (this.inputValue !== undefined && this.inputValue !== null) {
				      keyword = this.inputValue.toLowerCase();
				  }else{
					  this.items
				  }
			        this.queryResult  = this.items.filter(item => {
			            return (
							(item.waybillNumber !== null &&item.waybillNumber.toLowerCase().includes(keyword)) ||
							(item.description !== null &&item.description.toLowerCase().includes(keyword)) ||
							(item.putUserName !== null &&item.putUserName.toLowerCase().includes(keyword)) ||
							(item.putPlane !== null &&item.putPlane.toLowerCase().includes(keyword))
			            );
			        });
					// this.items=this.queryResult;
			    },
			handleLeftClick() {
			      // 处理左按钮点击事件，比如返回上一页
			      uni.navigateBack();
			    },
			    handleRightClick() {
			      // 处理右按钮点击事件，比如打开设置页面
			      uni.showToast({
			        title: '打开设置',
			        icon: 'none'
			      });
			      // 这里可以添加跳转到设置页面的逻辑
			    },
				showInputModal(item, index) {
					console.log(this.phone);
				      this.$refs.inputModal.showModal('筛选', {
				        onConfirm: (value) => {
				          console.log('用户输入:', value);
				          // 在这里处理用户输入的内容
				        },
				        onCancel: () => {
				          console.log('用户取消了输入');
				        }
				      },this.phone);
				    },
					confirm(data){
						console.log(data);
						this.items=data
						this.queryResult=data
					},
			  }
		}
</script>

<style scoped>
@import "select.css";
</style>
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      